package com.xs.langchain4j_springboot.spillter;

import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.DocumentSplitter;
import dev.langchain4j.data.segment.TextSegment;
import lombok.AllArgsConstructor;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@AllArgsConstructor
public class CommaDocumentSplitter implements DocumentSplitter {
    @Override
    public List<TextSegment> split(Document document) {
        String[] parts = document.text().split(",");
        return Arrays.stream(parts)
                .map(String::trim)
                .map(TextSegment::from)
                .collect(Collectors.toList());
    }

    @Override
    public List<TextSegment> splitAll(List<Document> documents) {
        return DocumentSplitter.super.splitAll(documents);
    }

/*    @Override
    public List<TextSegment> split(Document document) {
        String[] parts = document.text().split(",");
        return Arrays.stream(parts)
                .map(String::trim)
                .map(content -> Document.builder()
                        .content(content)
                        .metadata(document.metadata())
                        .build())
                .collect(Collectors.toList());
    }*/
}

